package com.kapcb.mvc.exception;

import com.kapcb.common.enums.ResultCodeEnum;
import lombok.Getter;

/**
 * <a>Title: BusinessLogicException </a>
 * <a>Author: kapcb <a>
 * <a>Description: 业务逻辑异常 <a>
 *
 * @author Kpacb
 * @version 1.0
 * @date 2024/4/28 21:52
 * @since 1.0
 */
@Getter
public class BusinessLogicException extends RuntimeException {


    private static final long serialVersionUID = 7976607349708608935L;

    /**
     * 错误码
     */
    private final Integer code;

    public BusinessLogicException() {
        this(ResultCodeEnum.BUSINESS_ERROR.code(), ResultCodeEnum.BUSINESS_ERROR.message());
    }

    public BusinessLogicException(String message) {
        this(ResultCodeEnum.BUSINESS_ERROR.code(), message);
    }

    public BusinessLogicException(Integer code, String message) {
        super(message);
        this.code = code;
    }

//    public BusinessLogicException(Result result) {
//        this(result.code(), result.message());
//    }

    public BusinessLogicException(ResultCodeEnum resultCodeEnum) {
        this(resultCodeEnum.code(), resultCodeEnum.message());
    }

    protected BusinessLogicException(Throwable throwable) {
        this(ResultCodeEnum.BUSINESS_ERROR.code(), throwable);
    }

    protected BusinessLogicException(Integer code, Throwable cause) {
        super(cause);
        this.code = code;
    }

    protected BusinessLogicException(Integer code, String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.code = code;
    }

}
